package com.rick.awarenessdemo.base

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.GsonUtils
import com.rick.awarenessdemo.util.LogUtil

abstract class BaseActivity<T : ViewDataBinding>(
    private val layoutId: Int,
    private val isFullScreen: Boolean = false // 是否沉浸状态栏
) : AppCompatActivity() {

    protected val binding: T by lazy {
        DataBindingUtil.setContentView<T>(this, layoutId)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        LogUtil.log(
            "onCreate ${javaClass.simpleName} ${
                GsonUtils.toJson(
                    ActivityUtils.getActivityList().map { it.javaClass.simpleName })
            }"
        )
        BarUtils.setStatusBarLightMode(this, true) // 状态栏文字黑色
        BarUtils.transparentStatusBar(this)
        if (!isFullScreen) {
            BarUtils.addMarginTopEqualStatusBarHeight(binding.root)
        }
        init(savedInstanceState, binding)
    }

    override fun onNewIntent(intent: Intent?) {
        LogUtil.log("onNewIntent ${javaClass.simpleName} ${GsonUtils.toJson(intent)}")
        super.onNewIntent(intent)
    }

    override fun onDestroy() {
        LogUtil.log("onDestroy ${javaClass.simpleName}")
        super.onDestroy()
    }

    abstract fun init(savedInstanceState: Bundle?, binding: T)
}